<?php
class useradmin extends database{
// add ------
	public function Add($username, $password){				
		if(!$this->isChar($username)){
			return 2;
		}else if(!$this->isLen($username,5,20)){
			return 3;
		}else if(!$this->isChar($password)){
			return 4;
		}else if(!$this->isLen($password,32,32)){
			return 5;
		}else{
			if($this->GetByName($username)==1){
				$sql="insert into useradmin(username, password, type, status) values('".$username."', '".$password."', 1, 1)";		
				if($result=$this->query($sql)){
					return 1;
				}else{
					return 0;
				}	
			}
			return -1;
		}
	}
// edit ------
	public function EditPass($username, $password){					
		if(!$this->isChar($username)){
			return 2;
		}else if(!$this->isLen($username,3,50)){
			return 3;
		}else if(!$this->isChar($password)){
			return 4;
		}else if(!$this->isLen($password,32,32)){
			return 5;
		}else{
			$sql="update useradmin set password='".$password."' where username = '".$username."'";	
			if($result=$this->query($sql)){
				return 1;
			}else{
				return 0;
			}	
		}
	}
// get by id
	public function GetByName($username){	
		if(!$this->isChar($username)){
			return 2;
		}else{	
			$sql="select username, password from useradmin where username='".$username."'";
			if($result=$this->query($sql)){
				if($this->CountRow($result)>0){
					while(($a=$this->fetch($result))!=NULL){
						$ds_sp[]=$this->unvalid($a); 
					}
					return $ds_sp;		
				}else{
					return 1;
				}
			}
		}
		return 0;
	}
	public function Login($username, $password){	
		if(!$this->isChar($username)){
			return 2;
		}else if(!$this->isChar($password)){
			return 3;
		}else{	
			$sql="select username, password from useradmin where username='".$username."' and password='".$password."' and status=1";
			if($result=$this->query($sql)){
				if($this->CountRow($result)>0){
					while(($a=$this->fetch($result))!=NULL){
						$ds_sp[]=$this->unvalid($a); 
					}
					return $ds_sp;		
				}else{
					return 4;
				}
			}
		}
		return 5;
	}
}
?>